﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Web;

namespace Bmz.Studio.Phone.Domain
{
    public class AppViewSettings
    {
        private static Dictionary<string, string> allView = new Dictionary<string, string>();
        private static void Init()
        {
            allView.Clear();
            Type type = typeof(StructInformationType);
            FieldInfo[] fields = type.GetFields();
            string key = string.Empty;
            foreach (FieldInfo field in fields)
            {
                key = string.Format("List.{0}.View", field.Name);
                if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
                {
                    allView.Add(key, ConfigurationManager.AppSettings[key]);
                }
                else
                {
                    allView.Add(key, ConfigurationManager.AppSettings["List.Default.View"]);
                }
                key = string.Format("Detail.{0}.View", field.Name);
                if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
                {
                    allView.Add(key, ConfigurationManager.AppSettings[key]);
                }
                else
                {
                    allView.Add(key, ConfigurationManager.AppSettings["Detail.Default.View"]);
                }
            }
        }
        public static string GetViewName(string pageType, string InfoType)
        {
            if (allView.Count< 1)
                Init();
            string key = string.Format("{0}.{1}.View", pageType, InfoType);
            if (allView.ContainsKey(key))
                return allView[key];
            return string.Empty;
        }
    }
}